package com.dwei.first.example;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

public class TestServer {

    public static void main(String[] args) throws Exception {
        // 事件循环组
        EventLoopGroup bossGroup = new NioEventLoopGroup(); // 不断从客户端接收连接，不做任何工作，获取后转给workgroup
        EventLoopGroup workerGroup = new NioEventLoopGroup(); //

        try {
            ServerBootstrap serverBootstrap = new ServerBootstrap();// 服务端启动
            serverBootstrap.group(bossGroup, workerGroup)
                    .channel(NioServerSocketChannel.class)
                    .childHandler(new TestServerInitializer()); //子处理器

            ChannelFuture channelFuture = serverBootstrap.bind(8899).sync();
            channelFuture.channel().closeFuture().sync();
        } finally {
            bossGroup.shutdownGracefully();
            workerGroup.shutdownGracefully();
        }
    }
}
